package com.qn.example.mapper;

import com.qn.example.pojo.Dish;
import com.qn.example.pojo.dto.DishDto;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author 21276
 * @version 1.0
 * @date 2023/5/5 10:05
 */
public interface DishMapper {

    //查询菜品，判断是有关联的菜品
    @Select("select count(*) from dish where category_id = #{id}")
    Integer findDishCountByCategoryId(Long id);

    //分页查询
    List<Dish> findByPage(@Param("name") String name);


    @Insert("insert into  dish values(null,#{name},#{categoryId},#{price},#{code},#{image},#{description},#{status},#{sort},#{createTime},#{updateTime},#{createUser},#{updateUser},0)")
    @Options(useGeneratedKeys = true,keyColumn = "id",keyProperty = "id") //useGeneratedKeys = true 插入之后将主键自动封装到当前实体类对象。
    void save(DishDto dishDto);

    //根据id查找菜品
    @Select("select * from dish where id=#{id}")
    Dish findById(Long id);

    void updateDish(DishDto dishDto);

    //删除完多个口味信息，在删除多个菜品信息
    void deleteids(@Param("ids") List<Long> ids);

    void dishStatusByStatus(@Param("status") Integer status , @Param("ids") List<Long> ids,@Param("updateTime") LocalDateTime updateTime);

    @Select("select * from dish where category_id = #{categoryId} ")
    List<Dish> list(Long categoryId);

    List<Dish> findByCategoryId(Long categoryId, Integer status);
}
